﻿
Namespace DoFactory.GangOfFour.Strategy.Structural


    ''' <summary>
    ''' MainApp startup class for Structural
    ''' Strategy Design Pattern.
    ''' </summary>
    Public Class MainApp


        ''' <summary>
        ''' Entry point into console application.
        ''' </summary>
        Public Shared Sub Main()

            Dim context As Context

            ' Three contexts following different strategies
            context = New Context(New ConcreteStrategyA())
            context.ContextInterface()

            context = New Context(New ConcreteStrategyB())
            context.ContextInterface()

            context = New Context(New ConcreteStrategyC())
            context.ContextInterface()

            ' Wait for user
            'Console.ReadKey()

        End Sub

    End Class

    ''' <summary>
    ''' The 'Strategy' abstract class
    ''' </summary>
    MustInherit Class Strategy

        Public MustOverride Sub AlgorithmInterface()

    End Class

    ''' <summary>
    ''' A 'ConcreteStrategy' class
    ''' </summary>
    Class ConcreteStrategyA
        Inherits Strategy

        Public Overrides Sub AlgorithmInterface()
            Console.WriteLine("Called ConcreteStrategyA.AlgorithmInterface()")
        End Sub

    End Class

    ''' <summary>
    ''' A 'ConcreteStrategy' class
    ''' </summary>
    Class ConcreteStrategyB
        Inherits Strategy

        Public Overrides Sub AlgorithmInterface()
            Console.WriteLine("Called ConcreteStrategyB.AlgorithmInterface()")
        End Sub

    End Class

    ''' <summary>
    ''' A 'ConcreteStrategy' class
    ''' </summary>
    Class ConcreteStrategyC
        Inherits Strategy

        Public Overrides Sub AlgorithmInterface()
            Console.WriteLine("Called ConcreteStrategyC.AlgorithmInterface()")
        End Sub

    End Class


    ''' <summary>
    ''' The 'Context' class
    ''' </summary>
    Class Context

        Private _strategy As Strategy

        ' Constructor
        Public Sub New(ByVal strategy As Strategy)
            Me._strategy = strategy
        End Sub

        Public Sub ContextInterface()
            _strategy.AlgorithmInterface()
        End Sub

    End Class

End Namespace
